define(['jquery', 'bootstrap', 'select2', 'validate', 'validate.en', 'koala-search', 
        'shiftform', 'modalSearch', 'datetimepicker', 'datetimepickerCN'],
        
function($, validate) {
  
  return {
    
    init: function() {
      this.initPage();
      this.initCompany();
      this.initClient();
      this.triggerModalSearch();
    },
    
    initPage: function(){
      $(document).find('form').bind('reset', function(e){
        $(this).find(".select2").select2("val", "");
      })
        
      $(document).find('form').bt_validate();
      
      $('select[name="organizationId"]').select2({
        theme: "classic",
        placeholder : '请选择',
        minimumResultsForSearch : -1,
        allowClear : true,
      });
      
      $('select[name="collectStatus"]').select2({
        theme: "classic",
        placeholder : '请选择',
        minimumResultsForSearch : -1,
        allowClear : true,
      });
      
      $('.date').datetimepicker({
        format: 'yyyy-mm-dd',
        autoclose: true,
        language: 'zh-CN',
        todayBtn: 'linked',
        startDate: '${today}',
        todayHighlight: true,
        pickerPosition: 'bottom-right',
        minView: 'month'
      });
      
      $(document).on('keyup', 'textarea[name=loadNumbers]', function() {
        var listVal = $(this).val();
        if (listVal != '') {
          var listSize = listVal.split('\n').length;
          $('span.loadNumbers-row-size').text(listSize);
          if (listSize > 999) {
            alert('最多999个参数');
          }
        }
      });
      
    },
    
    initCompany:function() {
      
      $('[data-target="#modal-search-company"]').modalsearch({
        url: window.__CTX__.root + '/transportation-companys/query',
        tableColumns: ['运输公司代码', '运输公司名称'],
        tableValues: ['code', 'name'],
        displayValues: ['code', 'name'],
        values: ['id']
      });
      
       
      var options = {
        time: 1000,
        url: window.__CTX__.root + "/transportation-companys/query",
        queryName: "code",
        value: ["id"],
        display: ["code", "name"]
      }
     
      $('.company-search').koalaSearch(options);
    },
    
    initClient:function() {
      
      $('[data-target="#modal-search-client"]').modalsearch({
        url: window.__CTX__.root + '/clients/query',
        tableColumns: ['客户代码', '客户名称'],
        tableValues: ['code', 'name'],
        displayValues: ['code', 'name'],
        values: ['id']
      });
      
      var options = {
        time: 1000,
        url: window.__CTX__.root + "/clients/query",
        queryName: "code",
        value: ["id"],
        display: ["code", "name"]
      }
      
      $('.client-search').koalaSearch(options);
    },
    
    triggerModalSearch: function() {
      $('.modal-search').each(function() {
        var value = $(this).val();
        console.info(value);
        if (value) {
          $(this).trigger('blur');
        }
      });
    }
    
  }
})